#include <iostream>
#include "lmanagerservice_impl.h"
#include <vector>
#include "lmanager.h"
#include "tools.h"
#include<iomanip>
using namespace std;
using namespace MC;

vector<Lmanager*> managers;

LmanagerServiceImpl::LmanagerServiceImpl()
{
	dao = new LmanagerDaoFileImpl;
}
bool LmanagerServiceImpl::addManager(Lmanager& man)
{
	dao->load(managers);
	managers.push_back(&man);
	dao->save(managers);
	return true;
}
bool LmanagerServiceImpl::deleteManager(int _id)
{
	managers.clear();
	dao->load(managers);
	vector<Lmanager*>::iterator itor;
	for(itor = managers.begin();itor !=managers.end();itor++)
	{
		if((*itor)->get_id() == _id)
		{
			itor = managers.erase(itor);
			dao->save(managers);
			return true;
		}
	}
	
	return false;
}
void LmanagerServiceImpl::listManager(void)
{
	managers.clear();
	dao->load(managers);
	cout << "\e[35m管理员ID\t\t\e[0m" << left << setw(23) << "\e[35m管理员姓名\t\t\e[0m" << left << setw(26) << "\e[35m管理员密码\t\t\e[0m" << endl;
	for(unsigned int i =0 ; i<managers.size();i++)
	{
		cout << managers.at(i)->get_id() << "\t\t         " << managers.at(i)->get_name() << "\t\t         " << managers.at(i)->get_password() <<endl;
	}
	
}
LmanagerServiceImpl::~LmanagerServiceImpl(void)
{
	delete []dao;
}
